package com.learn.spark.util

import org.apache.commons.lang3.time.FastDateFormat

import java.util.Date

object DateUtil extends Serializable {
  def parseDate(time: String): String = {
    try {
      val SOURCE_FORMAT: FastDateFormat = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss")
      val TARGET_FORMAT: FastDateFormat = FastDateFormat.getInstance("yyyy-MM-dd")
      val sourceDate: Date = SOURCE_FORMAT.parse(time)
      return TARGET_FORMAT.format(sourceDate)
    } catch {
      case e: Exception => println(e)
    }
    null
  }
}
